<?php

namespace app\api\controller\v1;

use app\api\controller\Base;
use app\api\service\R;
use think\facade\Request;
use \app\common\model\StDept as StDeptModel;
use \app\common\validate\StDept as StDeptValidate;

class StDept extends Base
{

    public function syncStDept(Request $request){
        if (!$this->request->isPost())  return R::error();

        $data = $request::getInput();
        $data = $this->twoDimensionalArray($data);
        // 验证
        $result = $this->validate($data[0], 'StDept');
        if(true !== $result) return $result;

        if ((new StDeptModel())->saveDeptData($data)) {
            return R::success();
        };

    }



    public function deleteStDept(Request $request){
        if ($this->request->isDelete()) {
            $deptId = $request::param('deptCode');
            if($deptId==null) R::error('请求参数异常');
            if (StDeptModel::destroy(['code'=>$deptId,'comid'=>COMID])) {
                return R::success();
            };
        }
        return R::error();
    }
}